package com.ajx.cube.module.splash.lancher;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.ajx.cube.R;
import com.bigkoo.convenientbanner.holder.Holder;

public class LauncherViewHolder implements Holder<Integer> {

    private final int lastPosition;
    private View launcherView;
    private ImageView imageView;
    private View btn;
    private OnEnterClickListener onEnterClickListener;

    public LauncherViewHolder(int size) {
        this.lastPosition=size-1;
    }


    @Override
    public View createView(final Context context) {
        launcherView = LayoutInflater.from(context).inflate(R.layout.item_launcher, null, false);
        imageView = launcherView.findViewById(R.id.launcher_image);
        btn = launcherView.findViewById(R.id.start_button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEnterClickListener!=null){
                    onEnterClickListener.onEnterClick();
                }
            }
        });
        return launcherView;
    }

    @Override
    public void UpdateUI(Context context, int position, Integer data) {
        if (position == lastPosition) {
            btn.setVisibility(View.VISIBLE);
        }
        imageView.setImageResource(data);
    }

    public interface OnEnterClickListener {
        void onEnterClick();
    }

    public void setOnEnterClickListener(OnEnterClickListener onEnterClickListener) {
        this.onEnterClickListener = onEnterClickListener;
    }
}